*ssc install mplotoffset
*ssc install sencode
*ssc install encodelabel
*net install brewscheme, from"https://wbuchanan.github.io/brewscheme")
*ssc install tuples
*ssc install spineplot
*ssc install estout
*ssc install brewscheme
*ssc install fre
*ssc install balancetable
*ssc install tabout


log using " ", text replace


**********************************
* 0.0 Housekeeping
**********************************

version 18
clear all
graph set window fontface "Arial"


//Working directory
cd " "

 
*Uploading Data	  
use "migrants_kuwait_qatar_dataset.dta"



*********************************
* 1.0 Descriptive Statistics
*********************************

// Table 1
 
table (var) (Country), ///
statistic(fvpercent gender)  ///
statistic(mean respage)  ///
statistic(sd respage)  ///
statistic(mean educ)  ///
statistic(sd educ)  ///
statistic(mean passport_rank)  ///
statistic(sd passport_rank)  ///
statistic(mean foreigners)  ///
statistic(sd foreigners)  ///
statistic(fvfrequency country_category) ///
nformat(%9.0fc fvfrequency) ///
sformat("%s%%" fvpercent) ///
nformat(%9.1f) ///
style(table-1)


* Collect the table content
collect style row stack, nobinder spacer
collect style cell border_block, border(right, pattern(nil))
collect preview
collect export migrants_stats.tex, replace



	  
****************************************
* 2.0 Regression Models: Main Paper
****************************************

// Table 2: Support for Increasing the Number of Foreign Workers

*Model 1
quietly regress foreigners ///
		ib(3).migrant_groups ///
		i.Country, robust			
eststo ols_1


*Model 2
quietly regress foreigners ///
		log_passport_rank_rev ///
		i.Country, robust		
eststo ols_2


*Model 3
quietly regress foreigners ///
		ib(3).migrant_groups ///
        respage ///
	    i.gender_factor ///
		educ ///
		i.Country, robust		
eststo ols_3


*Model 4		
quietly regress foreigners ///
		log_passport_rank_rev ///
        respage ///
	    i.gender_factor ///
		educ ///
		i.Country, robust		
eststo ols_4

	
		
* Combine OLS models in one table
esttab ols_1 ols_2 ols_3 ols_4, replace ///   
	   se nobaselevels  ///
	   star(+ 0.1 * 0.05 ** 0.01 *** 0.001) ///
	   stats(N r2, fmt(0 3) label(N R-Squared)) ///
	   title("Support for Foreign Workers") 	///	
	   coeflabel(respage "Age" ///
	   educ "Education" ///
	   2.gender_factor "Female" ///
	   income "Income (1-2)" ///
	   sqrt_passport_rank_rev "sqrt_passport" ///
	   log_passport_rank_rev "Log of Henley Passport Index" ///
	   2.migrant_groups "Arab Migrants (base: Non-Arab Migrants)" ///
	   3.migrant_groups "Non-Arab Migrants" ///
	   2.migrant_groups#2.edu_cat "High educ#Arab Migrants" ///
	   3.migrant_groups#2.edu_cat "High educ#Non-Arab Migrants" ///
	   2.Country "Kuwait (base: Qatar)" ///
	   _cons "Constant") ///
	   order(2.migrant_groups ///
	         log_passport_rank_rev ///
			 respage  ///
			 2.gender_factor ///
		     educ ///
		     2.Country) 


	 
****************************************
* 2.0 Regression Models: Appendix
****************************************	  

// Appendix Table 1: Support for Increasing the Number of Foreign Workers by Country
	
// For Qatar

*Model 1
quietly regress foreigners ///
		ib(3).migrant_groups ///
		if Country == 1, robust	
eststo ols_1_q


*Model 2
quietly regress foreigners ///
	    log_passport_rank_rev ///
		if Country == 1, robust	
eststo ols_2_q


*Model 3
quietly regress foreigners ///
		ib(3).migrant_groups ///
        respage ///
	    i.gender_factor ///
		educ ///
		if Country == 1, robust		
eststo ols_3_q


*Model 4		
quietly regress foreigners ///
		log_passport_rank_rev ///
        respage ///
	    i.gender_factor ///
		educ ///
		if Country == 1, robust		
eststo ols_4_q





// For Kuwait


*Model 5
quietly regress foreigners ///
		ib(3).migrant_groups ///
		if Country == 2, robust	
eststo ols_1_k


*Model 6
quietly regress foreigners ///
		log_passport_rank_rev ///
		if Country == 2, robust	
eststo ols_2_k


*Model 7
quietly regress foreigners ///
		ib(3).migrant_groups ///
        respage ///
	    i.gender_factor ///
		educ ///
		if Country == 2, robust		
eststo ols_3_k


*Model 8		
quietly regress foreigners ///
		log_passport_rank_rev ///
        respage ///
	    i.gender_factor ///
		educ ///
		if Country == 2, robust	
eststo ols_4_k



	
* Combine models in one table (Appendix Table 1: Support for Increasing the Number of Foreign Workers by Country)

esttab ols_1_q ols_2_q ols_3_q ols_4_q ///
       ols_1_k ols_2_k ols_3_k ols_4_k, replace ///   
	   se nobaselevels  ///
	   star(+ 0.1 * 0.05 ** 0.01 *** 0.001) ///
	   stats(N r2, fmt(0 3) label(N R-Squared)) ///
	   title("Support for Foreign Workers") 	///	
	   coeflabel(respage "Age" ///
	   educ "Education" ///
	   2.gender_factor "Female" ///
	   income "Income (1-2)" ///
	   sqrt_passport_rank_rev "sqrt_passport" ///
	   log_passport_rank_rev "Log of Henley Passport Index" ///
	   2.migrant_groups "Arab Migrants (base: Non-Arab Migrants)" ///
	   3.migrant_groups "Non-Arab Migrants" ///
	   2.migrant_groups#2.edu_cat "High educ#Arab Migrants" ///
	   3.migrant_groups#2.edu_cat "High educ#Non-Arab Migrants" ///
	   2.Country "Kuwait (base: Qatar)" ///
	   _cons "Constant") ///
	   order(2.migrant_groups ///
	         log_passport_rank_rev ///
			 respage  ///
			 2.gender_factor ///
		     educ)
	 

	 
	 
**************************************
* 3.1 Wording Expriment Settup
**************************************

* Set conjoint categories: Round 1

* Arabic

gen conjoint1 = .
replace conjoint1 = 1 if tfRnd_1 == "إذا كانت الحكومة تفكر في تغيير عدد العمال الأجانب في قطر، فما هو مستوى الأولوية التي ستعطيها لـلأطباء العرب؟" | tfRnd_1 == "إذا كانت الحكومة تفكر في تغيير عدد العمال الأجانب في الكويت فما هو مستوى الأولوية التي ستعطيها لـلأطباء العرب؟"

replace conjoint1 = 2 if tfRnd_1 == "إذا كانت الحكومة تفكر في تغيير عدد العمال الأجانب في قطر، فما هو مستوى الأولوية التي ستعطيها لـلأطباء الهنود؟" | tfRnd_1 == "إذا كانت الحكومة تفكر في تغيير عدد العمال الأجانب في الكويت، فما هو مستوى الأولوية التي ستعطيها لـلأطباء الهنود؟"

replace conjoint1 = 3 if tfRnd_1 == "إذا كانت الحكومة تفكر في تغيير عدد العمال الأجانب في قطر، فما هو مستوى الأولوية التي ستعطيها لعمال البناء العرب؟" | tfRnd_1 == "إذا كانت الحكومة تفكر في تغيير عدد العمال الأجانب في الكويت، فما هو مستوى الأولوية التي ستعطيها لعمال البناء العرب؟"

replace conjoint1 = 4 if tfRnd_1 == "إذا كانت الحكومة تفكر في تغيير عدد العمال الأجانب في قطر، فما هو مستوى الأولوية التي ستعطيها لعمال البناء الهنود؟" | tfRnd_1 == "إذا كانت الحكومة تفكر في تغيير عدد العمال الأجانب في الكويت، فما هو مستوى الأولوية التي ستعطيها لعمال البناء الهنود؟"



* English
replace conjoint1 = 1 if tfRnd_1 == "If Qatar were thinking about changing the number of foreign workers in Qatar, what level of priority would you give to Arab doctors?" | tfRnd_1 == "If Kuwait were thinking about changing the number of foreign workers in Kuwait, what level of priority would you give to Arab doctors?"

replace conjoint1 = 2 if tfRnd_1 == "If Qatar were thinking about changing the number of foreign workers in Qatar, what level of priority would you give to South Asian doctors?" | tfRnd_1 == "If Kuwait were thinking about changing the number of foreign workers in Kuwait, what level of priority would you give to South Asian doctors?"

replace conjoint1 = 3 if tfRnd_1 == "If Qatar were thinking about changing the number of foreign workers in Qatar, what level of priority would you give to Arab construction workers?" | tfRnd_1 == "If Kuwait were thinking about changing the number of foreign workers in Kuwait, what level of priority would you give to Arab construction workers?"

replace conjoint1 = 4 if tfRnd_1 == "If Qatar were thinking about changing the number of foreign workers in Qatar, what level of priority would you give to South Asian construction workers?" | tfRnd_1 == "If Kuwait were thinking about changing the number of foreign workers in Kuwait, what level of priority would you give to South Asian construction workers?"



* Set conjoint categories: Round 2

* Arabic

gen conjoint2 = .
replace conjoint2 = 1 if tfRnd_2 == "وما هو مستوى الأولوية التي ستعطيها لـلأطباء العرب؟"
replace conjoint2 = 2 if tfRnd_2 == "وما هو مستوى الأولوية التي ستعطيها لـلأطباء الهنود؟"
replace conjoint2 = 3 if tfRnd_2 == "وما هو مستوى الأولوية التي ستعطيها لـعمال البناء العرب؟"
replace conjoint2 = 4 if tfRnd_2 == "وما هو مستوى الأولوية التي ستعطيها لـعمال البناء الهنود؟"

* English
replace conjoint2 = 1 if tfRnd_2 == "And what level of priority would you give to  Arab doctors?"
replace conjoint2 = 2 if tfRnd_2 == "And what level of priority would you give to  South Asian doctors?"
replace conjoint2 = 3 if tfRnd_2 == "And what level of priority would you give to  Arab construction workers?"
replace conjoint2 = 4 if tfRnd_2 == "And what level of priority would you give to  South Asian construction workers?"


* Labels
label define conjoint 1 "Arab Doctors" 2 "Indian Doctors" 3 "Arab Construction" 4 "Indian Construction", replace
label values conjoint1 conjoint
label values conjoint2 conjoint

* Wording Experiment Settup
reshape long conjoint FOREIGN_VIGNETTE, i(id_n) j(contest_no) 

* Drop missing from DV
replace FOREIGN_VIGNETTE = . if FOREIGN_VIGNETTE<0

* Reversing the scale to be more intuitive in the regression
revrs FOREIGN_VIGNETTE, replace




*********************************************
* 4.0 Wording Expriment: Plots in the Paper
*********************************************



// For both Qatar and Kuwait
// Figure 1: Migrant Worker Prioritization among Arab and non-Arab Migrants


ologit FOREIGN_VIGNETTE conjoint#i.migrant_groups foreigners, robust
  
margins conjoint#i.migrant_groups, predict(outcome(4))

marginsplot, ///
title(" ", margin(medium) size(3.9) nospan) ///
xtitle(" ", margin(small) size(3.3)) ///
ytitle("Probability of High Prioritization", margin(medium) size(3.2)) ///
xlab( 1 `""Arab""Doctors""' ///
 2 `""Indian""Doctors""' ///
 3 `""Arab"" Construction""' ///
 4 `""Indian"" Construction""', nogrid labsize(3.1)) ///
 ylabel(, grid labsize(3.3)) ///
scheme(s2color) ///
aspectratio(0.85) ///
plot1opts(msymbol(D) msize(1.6) mcolor(navy%95*0.8) lcolor(none)) ///
plot2opts(msymbol(O) msize(2) mcolor(gold%95*1.2) lcolor(none)) ///
ciopts(recast(rcap) lcolor(grey%95*0.4) msize(2.8)) ///
graphregion(color(white) margin(small)) plotregion(margin(t = 3 b = 3 r = 8 l = 5)) ///
 legend(region(margin(small)) ///
 bmargin(tiny) ///
 size(3.3) r(1) symxsize(small) symysize(small) ///
 pos(6) ring(1))
	  
graph save figure_1_all.gph, replace






// For both Qatar and Kuwait
// Figure 2: Support for Migration and Migrant Worker Prioritization among Arab Migrants


ologit FOREIGN_VIGNETTE conjoint#i.migrant_groups foreigners if migrant_groups == 2, robust
  
margins conjoint, at(foreigners=(1(1)5)) predict(outcome(4))

marginsplot, ///
title("", margin(small) size(3) nospan) ///
xtitle(" ", margin(small) size(3)) ///
ytitle("Probability of High Prioritization", margin(medium) size(3.2)) ///
xlab( 1 `""Decrease""a Lot""' ///
 2 `""Decrease""Somewhat""' ///
 3 `""Stay"" the Same""' ///
 4 `""Increase"" Somewhat""' ///
 5 `""Increase""a Lot""' , nogrid labsize(3.1)) ///
 ylabel(0(0.2)0.8, nogrid labsize(3.2)) ///
scheme(s2color) ///
aspectratio(0.8) ///
plot1opts(lpattern() msymbol(D) msize(1.55) mcolor(ebblue%95*1.4) lcolor(ebblue%95*1.4)) ///
plot2opts(lpattern() msymbol(T) msize(1.55) mcolor(green%95*1.4) lcolor(green%95*1.4)) ///
plot3opts(lpattern() msymbol(D) msize(1.55) mcolor(ebblue%95*0.6) lcolor(ebblue%95*0.6)) ///
plot4opts(lpattern() msymbol(T) msize(1.55) mcolor(green%95*0.6) lcolor(green%95*0.6)) ///
ciopts(recast(rcap) lcolor(grey%95*0.4) msize(2.7)) ///
graphregion(color(white) margin(small)) plotregion(margin(r = 7 l = 7)) ///
 legend(region(margin(small)) ///
 bmargin(tiny) ///
 size(3.2) r(2) symxsize(small) symysize(small) ///
 pos(6) ring(1))


graph save fig2_experiment.gph, replace	  





************************************************
* 5.0 Wording Expriment: Plots in the appendix
************************************************

//  Appendix Figure 1: Migrant Worker Prioritization among Arab and non-Arab Migrants by Country

// For Qatar

ologit FOREIGN_VIGNETTE conjoint#i.migrant_groups foreigners if Country == 1, robust
  
margins conjoint#i.migrant_groups, predict(outcome(4))

marginsplot, ///
title("Qatar", margin(medium) size(3.9) nospan) ///
xtitle(" ", margin(small) size(3.3)) ///
ytitle("Probability of High Prioritization", margin(medium) size(3.2)) ///
xlab( 1 `""Arab""Doctors""' ///
 2 `""Indian""Doctors""' ///
 3 `""Arab"" Construction""' ///
 4 `""Indian"" Construction""', nogrid labsize(3.1)) ///
 ylabel(, grid labsize(3.3)) ///
scheme(s2color) ///
aspectratio(0.85) ///
plot1opts(msymbol(D) msize(1.6) mcolor(navy%95*0.8) lcolor(none)) ///
plot2opts(msymbol(O) msize(2) mcolor(gold%95*1.2) lcolor(none)) ///
ciopts(recast(rcap) lcolor(grey%95*0.4) msize(2.8)) ///
graphregion(color(white) margin(small)) plotregion(margin(t = 3 b = 3 r = 8 l = 5)) ///
 legend(region(margin(small)) ///
 bmargin(tiny) ///
 size(3.3) r(1) symxsize(small) symysize(small) ///
 pos(6) ring(1))
	  
graph save figure_1_qatar.gph, replace
	  

	  
// For Kuwait

ologit FOREIGN_VIGNETTE conjoint#i.migrant_groups foreigners if Country == 2, robust
  
margins conjoint#i.migrant_groups, predict(outcome(4))

marginsplot, ///
title("Kuwait", margin(medium) size(3.9) nospan) ///
xtitle(" ", margin(small) size(3.3)) ///
ytitle(" ", margin(medium) size(3.2)) ///
xlab( 1 `""Arab""Doctors""' ///
 2 `""Indian""Doctors""' ///
 3 `""Arab"" Construction""' ///
 4 `""Indian"" Construction""', nogrid labsize(3.1)) ///
 ylabel(, grid labsize(3.3)) ///
scheme(s2color) ///
aspectratio(0.85) ///
plot1opts(msymbol(D) msize(1.6) mcolor(navy%95*0.8) lcolor(none)) ///
plot2opts(msymbol(O) msize(2) mcolor(gold%95*1.2) lcolor(none)) ///
ciopts(recast(rcap) lcolor(grey%95*0.4) msize(2.8)) ///
graphregion(color(white) margin(small)) plotregion(margin(t = 3 b = 3 r = 8 l = 5)) ///
 legend(region(margin(small)) ///
 bmargin(tiny) ///
 size(3.3) r(1) symxsize(small) symysize(small) ///
 pos(6) ring(1))
	  
graph save figure_1_kuwait.gph, replace
	  


// Combine plots for figure 1: Migrant Worker Prioritization among Arab and non-Arab Migrants by Country

// graph drop migrants_exp_country
graph combine figure_1_qatar.gph figure_1_kuwait.gph , xcommon ycommon name(migrants_exp_country)






	  
**** Appendix Figure 2: Migrant Worker Prioritization among Low and High Educated Arab Migrants

// Less than University education  
  
quietly ologit FOREIGN_VIGNETTE conjoint#i.migrant_groups foreigners if educ < 7 & migrant_groups  == 2, robust

margins conjoint#i.migrant_groups, predict(outcome(4))

marginsplot, ///
title("Low Education", margin(medium) size(3.9) nospan) ///
xtitle(" ", margin(small) size(3.3)) ///
ytitle("Probability of High Prioritization", margin(medium) size(3.2)) ///
xlab( 1 `""Arab""Doctors""' ///
 2 `""Indian""Doctors""' ///
 3 `""Arab"" Construction""' ///
 4 `""Indian"" Construction""', nogrid labsize(3.1)) ///
 ylabel(, grid labsize(3.3)) ///
scheme(s2color) ///
aspectratio(0.85) ///
plot1opts(msymbol(D) msize(1.6) mcolor(navy%95*0.8) lcolor(none)) ///
ciopts(recast(rcap) lcolor(grey%95*0.4) msize(2.8)) ///
graphregion(color(white) margin(small)) plotregion(margin(t = 3 b = 3 r = 8 l = 5)) ///
 legend(region(margin(small)) ///
 bmargin(tiny) ///
 size(3.3) r(1) symxsize(small) symysize(small) ///
 pos(6) ring(1))
	  
graph save figure_2_low_educ.gph, replace
	  

	  
	  
	  
// Education level of undergraduate degee and above

quietly ologit FOREIGN_VIGNETTE conjoint#i.migrant_groups foreigners if educ >= 7 & migrant_groups  == 2, robust

margins conjoint#i.migrant_groups, predict(outcome(4))
  
marginsplot, ///
title("High Education", margin(medium) size(3.9) nospan) ///
xtitle(" ", margin(small) size(3.3)) ///
ytitle(" ", margin(medium) size(3.2)) ///
xlab( 1 `""Arab""Doctors""' ///
 2 `""Indian""Doctors""' ///
 3 `""Arab"" Construction""' ///
 4 `""Indian"" Construction""', nogrid labsize(3.1)) ///
 ylabel(, grid labsize(3.3)) ///
scheme(s2color) ///
aspectratio(0.85) ///
plot1opts(msymbol(D) msize(1.6) mcolor(navy%95*0.8) lcolor(none)) ///
ciopts(recast(rcap) lcolor(grey%95*0.4) msize(2.8)) ///
graphregion(color(white) margin(small)) plotregion(margin(t = 3 b = 3 r = 8 l = 5)) ///
 legend(region(margin(small)) ///
 bmargin(tiny) ///
 size(3.3) r(1) symxsize(small) symysize(small) ///
 pos(6) ring(1))
	  
graph save figure_2_high_educ.gph, replace



// Combine plots

// graph drop migrants_exp_arab_edu
graph combine figure_2_low_educ.gph figure_2_high_educ.gph, xcommon ycommon name(migrants_exp_arab_edu)
	


	
	
log close